package top.hkyzf.study.leetcode.string;

import org.junit.Test;

/**
 * @author 朱峰
 * @date 2022-2-23 10:43
 */
public class 仅仅反转字母_917 {
    public String reverseOnlyLetters(String s) {
        int left = 0;
        int right = s.length() - 1;
        char[] sch = s.toCharArray();
        br: while (left < right) {
            char chl = s.charAt(left);
            while (chl < 65 || (chl > 90 && chl < 97) || chl > 122) {
                left++;
                if (left < right) {
                    chl = s.charAt(left);
                } else {
                    break br;
                }
            }
            char chr = s.charAt(right);
            while (chr < 65 || (chr > 90 && chr < 97) || chr > 122) {
                right--;
                if (left < right) {
                    chr = s.charAt(right);
                } else {
                    break br;
                }
            }
            sch[left] = chr;
            sch[right] = chl;
            left++;
            right--;
        }
        return new String(sch);
    }

    @Test
    public void testReverseOnlyLetters () {
        String s = "a-bC-dEf-ghIj";
        System.out.println(reverseOnlyLetters(s));
    }
}
